KY-032 INFRARED OBSTACLE AVOIDANCE SENSOR MODULE

Click Here to View Step by Step

KY-032 INFRARED OBSTACLE AVOIDANCE SENSOR MODULE


Short description :

KY-032 Obstacle Avoidance Sensor module is a distance-adjustable, infrared proximity sensor.

Working with  (Compatible)

Arduino, ESP32, Nodemcu, ESP8266, Raspberry Pi, and ......

KY-032 INFRARED OBSTACLE AVOIDANCE SENSOR MODULE

KY-032 INFRARED OBSTACLE AVOIDANCE SENSOR MODULE

ARDUINO IDE CODE 

Example description :

When the sensor detects an obstacle, it sends a LOW signal on its output pin. A HIGH signal is sent when the obstacle is not detected or is out of range.

int ledPin = 13;      // LED pin on arduino
int detectorPin = 3;  // obstacle avoidance sensor interface
int val;              // variable to store result
//int enablePin = 2;  // sensor enable interface (EN)
void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  // Define LED as output interface
  pinMode(detectorPin, INPUT);  // Define obstacle avoidance sensor as input interface
  
  // [uncomment and remove jumper on module to use enable pin (EN)]
  //pinMode(enablePin, OUTPUT);
  //digitalWrite(enablePin, HIGH);  // Enable sensor
}
void loop()
{
  val = digitalRead(detectorPin); // Read value from sensor
    Serial.println(val);
  if(val == LOW) // When the sensor detects an obstacle, the LED on the Arduino lights up
  {
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}